package com.edu.robot.modules.robot.controller;

import com.edu.robot.model.R;
import com.edu.robot.modules.robot.controller.vo.ModelConfigVO;
import com.edu.robot.modules.robot.controller.vo.PageQuery;
import com.edu.robot.modules.robot.controller.vo.QueryModelVO;
import com.edu.robot.modules.robot.corvert.ModelConfigCovert;
import com.edu.robot.modules.robot.dto.ModelConfigDTO;
import com.edu.robot.modules.robot.service.CrModelConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-24 20:54
 **/

@RestController
@RequestMapping("/robot/model")
@Slf4j
public class ModelController {

	@Autowired
	private CrModelConfigService crModelConfigService;

	//新建模型
	@PostMapping("/add")
	public R<?> addModel(@RequestBody @Validated ModelConfigVO modelVO){

		log.info("ModelController addModel:{}",modelVO);

		ModelConfigDTO covert = ModelConfigCovert.covert(modelVO);
		return crModelConfigService.createModelConfig(covert);
	}

	/*
	* @author 范铁凝
	* @date 2025/4/14
	* 分页查询模型
	*/
	@PostMapping("/list")
	public R<?> listModel(@RequestBody @Validated PageQuery<QueryModelVO> queryModel){

		log.info("ModelController listModel:{}",queryModel);

		return R.success(crModelConfigService.queryModelList(queryModel));

	}

	/*
	* @author 范铁凝
	* @date 2025/4/14
	* 更新模型
	*/
	@PostMapping("/update")
	public R<?> updateModel(@RequestBody @Validated ModelConfigVO modelVO){

		log.info("ModelController updateModel:{}",modelVO);

		return crModelConfigService.updateModelConfig(modelVO);
	}

	/*
	* @author 范铁凝
	* @date 2025/4/14
	* 删除模型
	*/
	@DeleteMapping("/delete/{id}")
	public R<?> deleteModel(@PathVariable("id") String id){

		log.info("ModelController deleteModel:{}",id);
		if(crModelConfigService.removeById(id)){
			return R.success();
		}

		return R.fail("服务异常");
	}
}
